#include "RenderPipeline.h"

namespace egg{

    void RenderPipeline::drawCustom(RenderContext& _context,Drawable3D* _drawable,MaterialPass* _pass){
        gDevice->setRastState(_pass->getRastState());
        gDevice->setBlendState(_pass->getBlendState());
        gDevice->setDepthState(_pass->getDepthState());
        gDevice->setStencilState(_pass->getStencilState());
        _pass->activate(_context,_drawable->mLocal2WorldMatrix);
        _drawable->mGeometry->draw(DM_TRIANGLES);
    }

    void RenderPipeline::drawForwardLit(RenderContext& _context,Drawable3D* _drawable,MaterialPass* _pass){
        list<Light*>& lights=_context.mOrderedLights;
        list<Light*>::iterator itr=lights.begin();
        Light* light=*itr;
        light->activate(_context);
        gDevice->setDepthState(mDepthState);
        gDevice->setBlendState(mBlendState);
        gDevice->setRastState(_pass->getRastState());
        gDevice->setStencilState(_pass->getStencilState());
        _pass->activate(_context,_drawable->mLocal2WorldMatrix);
        _drawable->mGeometry->draw(DM_TRIANGLES);
        itr++;
        for(;itr!=lights.end();itr++){
            light->activate(_context);
            _pass->activate(_context,_drawable->mLocal2WorldMatrix);
            _drawable->mGeometry->draw(DM_TRIANGLES);
        }
    }

    void RenderPipeline::drawDeferredLit(RenderContext& _context,Drawable3D* _drawable,MaterialPass* _pass){
        gDevice->setDepthState(mDepthState);
        gDevice->setBlendState(mBlendState);
        gDevice->setRastState(_pass->getRastState());
        gDevice->setStencilState(_pass->getStencilState());
        _pass->activate(_context,_drawable->mLocal2WorldMatrix);
        _drawable->mGeometry->draw(DM_TRIANGLES);
    }

}